# coding=utf-8

from lxml import etree
'''通过打开文件然后读取内容，将读取到的内容当作etree.HTML'''
# with open('wocao' ,'r+', encoding='utf_8') as wfile:
#      contents = wfile.read()
# html = etree.HTML(content))
# etree.HTML()可以接收str或者bytes类型数据，将其转化成 Element 对象


# 从文件加载 HTML
html = etree.parse('TTFC系统输入格式定义',etree.HTMLParser())

# lxml 会自动修 HTML ，查看一下 lxml 修正后的结果
print(etree.tostring(html, pretty_print=True,encoding='utf8').decode('utf8'))

# 获取 Learning XML 这本书的价格
ret = html.xpath('//title[text()="Learning XML"]/following::price/text()')[0] if len(
    html.xpath('//title[text()="Learning XML"]/following::price/text()')) else None

print(ret)
##afxNetNODEs = html.xpath('//afxNetNODE')
#print(afxNetNODEs)
#for afxNetNODE in afxNetNODEs:
   # a = etree.tostring(afxNetNODE, encoding='utf8').decode('utf8')
    #print(a)